class FormUtilsTagLib {

    static namespace = 'fu'

    /**
     * This closure needs the following information to work correctly.
     * items - The items to list.
     * title - The title for the items.
     * controller - The controller to send the user to if the item is selected.
     * createParams - The parameters to pass into the controller to create a
     *                new instance. If this parameter does not exist then the 
     *                create link is not added.
     */
    def viewShortList = {attrs ->
        if (attrs.createParams) {
            println attrs.createParams
        }
        
        out << """
                <tr class="prop">
                  <td valign="top" class="name">
                    <label for="items">${attrs.title}:</label>
                  </td>
                  <td valign="top" class="value">"""
        if (attrs.items) {
            out << render(template:"/common/utils/viewShortList", model:[items:attrs.items, controller: attrs.controller])
        } else {
            out << "No ${attrs.title} found."
        }

//        if (attrs.createParams) {
//            println render(template:"/common/utils/link", model:[controller: attrs.controller, createParams: attrs.createParams, buttonText: attrs.title])
//            println "test = " + link(controller:attrs.controller, action:'create', "Create new View")
//            out << render(template:"/common/utils/link", model:[controller: attrs.controller, createParams: attrs.createParams, buttonText: attrs.title])
//        }
        out << """
                  </td>
                </tr>"""
    }
}


//def linkEachInCollection = { attrs ->
//	def propertyName = attrs['property']
//	def controllerName = attrs['controller']
//	attrs['collection'].each{
//		def prop
//		if (propertyName){
//			prop = it[propertyName]
//		} else {
//			prop = it.id
//		}
//		out << "<li>" +
//			link([controller:controllerName, action:'show', id:it.id]){prop} +
//			"</li>"
//	}
//}